#ifndef __CAN_MOTOR_CLASS__
#define __CAN_MOTOR_CLASS__
#include "pid.h"
#include "FreeRTOS.h"
#include "task.h"
#include "cmsis_os.h"

#ifdef __cplusplus
/**
 * @brief 	电机参数类
 */
class Can_motor_measure{
public:
    //电机运行状态枚举
    enum MOTOR_STATE{
        RUN = 0,
        STOP = 1,
        ANGLE_REL = 3,
        ANGLE_NO = 4,
				ANGLE_ABS = 5,
    };
    uint32_t stdID = 0;					//电机的标准canID

    float target_speed = 0;				//电机目标转速
    float target_angle = 0;			    //电机目标转过的角度值(用于角度环pid)

    float speed_rpm_now = 0;			//电机当前转速,单位:rpm
    float speed_rpm_last = 0;			//电机上次转速
    float angle_now = 0;				//电机转子当前角度	角度制	[0,360)
    float angle_last = 0;				//电机转子上次角度
    float angle_total = 0;				//电机转过总角度(用于角度环pid,正负代表不同方向)

    MOTOR_STATE state = STOP;				//电机运行状态	 RUN 或者 STOP
    MOTOR_STATE angle_mode = ANGLE_NO;		//角度环pid模式	ANGLE_YES（进行角度环）或者 ANGLE_NO（不进行角度环pid）

    void measure_config( MOTOR_STATE state,     //配置电机参数类的参数
                         MOTOR_STATE angle_mode,
                         uint32_t stdID);
    Can_motor_measure();
    virtual ~Can_motor_measure(){};
};
#endif

#ifdef __cplusplus
/*
 * @brief   电机对象基类,继承 Can_motor_measure
 */
class Can_motor : public Can_motor_measure
{
public:
    pid_t spid;     //速度环pid
    pid_t apid;     //角度环pid
    osMessageQId    can_msg_que = NULL;            //rtos消息队列句柄
    uint32_t        can_msg_que_size = 1;       //rtos消息队列尺寸

    void set_speed(float speed);            //速度环
    void set_rel_angle(float angle);        //角度环
    void set_abs_angle(float angle);        //角度环
    void set_stop();                        //不输出
    virtual void update_measure();          //更新数据

    Can_motor();                            //构造函数
    virtual ~Can_motor(){};                 //虚析构函数
};

#if 0
/*
 * @brief   3508电机派生类,继承 Can_motor
 */
class DJI_3508 : public Can_motor
{
public:

    void update_measure () override;
    DJI_3508(){};
    ~DJI_3508(){};
};

/*
 * @brief   2006电机派生类,继承 Can_motor
 */
class DJI_2006 : public Can_motor
{
public:

    void update_measure () override;
    DJI_2006(){};
    ~DJI_2006(){};
};

/*
 * @brief   6020电机派生类,继承 Can_motor
 */
class DJI_6020 : public Can_motor
{
public:

    void update_measure () override;
    DJI_6020(){};
    ~DJI_6020(){};
};
#endif

#endif

#endif
